package com.zhenghaijin.favoritesservice.controller;

import com.zhenghaijin.favoritesservice.model.Favorite;
import com.zhenghaijin.favoritesservice.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/favorites")
public class FavoriteController {
    @Autowired
    private FavoriteService favoriteService;

    @GetMapping("/user/{userId}")
    public List<Favorite> getFavorites(@PathVariable Long userId) {
        return favoriteService.getFavoritesByUserId(userId);
    }

    @GetMapping("/check")
    public boolean isFavorite(@RequestParam Long userId, @RequestParam Long animeId) {
        return favoriteService.isFavorite(userId, animeId);
    }

    @PostMapping
    public void addFavorite(@RequestBody Favorite favorite) {
        favoriteService.addFavorite(favorite);
    }

    @DeleteMapping
    public void removeFavorite(@RequestParam Long userId, @RequestParam Long animeId) {
        favoriteService.removeFavorite(userId, animeId);
    }
}

